/*************************************************************************
	> File Name: test7.c
	> Author: H.M. Lau
	> Mail: hm.lau@outlook.com
	> Created Time: 2023/09/02 22:38
 ************************************************************************/

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

int main(int argc, char *argv[])
{
    close(1);
    int fd = open("log.txt", O_WRONLY | O_TRUNC | O_CREAT, 0666);
    if (fd < 0) {
        perror("open");
        return 1;
    }
    printf("hello printf:%d\n", fd);
    fflush(stdout);
    const char *msg = "hello write\n";
    write(fd, msg, strlen(msg));
    close(fd);
    return 0;
}
